package learning.pcfg.inference;

import java.util.HashMap;
import java.util.Map;

public class Chart {

	private ChartCell[][] m_chartCells;
	
	public Chart(int inputLength) {
        m_chartCells = new ChartCell[inputLength][];
        for (int i = 0; i < inputLength; i++)
        {
            m_chartCells[i] = new ChartCell
                [inputLength - i];
        }
	}

	public ChartCell get(int begin, int end) {
		return m_chartCells[begin][end - begin - 1];		
	}
	
	public void set(int begin, int end, ChartCell cr) {
		m_chartCells[begin][end - begin - 1] = cr;
	}
	
	public static class ChartCell {
		
		public Map<Integer, Parse> m_chartEntries;
		
		public ChartCell() {
			this.m_chartEntries = new HashMap<Integer, Parse>();
		}
		
		public Parse get(int symbol) {
			return m_chartEntries.get(symbol);
		}
		
		public void set(int symbol, Parse parse) {
			m_chartEntries.put(symbol, parse);
		}
		
		public int size() {
			return m_chartEntries.size();
		}
	}
}
